﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;

namespace CIRDiagnoseDevice.Control
{
    public   class Config_SerialPort
    {
        /// <summary>
        /// 向测试仪表发送命令串口
        /// </summary>
        public SerialPort _2944SerialPort; //= new SerialPort(portName, baudeRate); 
        public SerialPort _4202SerialPort;
        public SerialPort TrainEndSerialPort;
        public SerialPort LbjSerialPort;
        public SerialPort PocsagCodePort;
        public SerialPort GsmFunSerialPort;
        public SerialPort TaxSerialPort;
        public SerialPort GSM_RModPort;
        public SerialPort PowerPort;
        public SerialPort OSP5;
        /// <summary>
        /// 向Lbj发送命令串口
        /// </summary>
        public SerialPort LbjNorSerialPort;
        public SerialPort LbjControlPort;
        public Config_SerialPort()
        {
            ReadiniFile initFile = new ReadiniFile(Application.StartupPath);
            List<string> list = new List<string>();
            list = initFile.ReadCommPort();
            string portName = string.Empty;
            int baudeRate = 0;
            string[] strArr = list[0].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            _2944SerialPort = new SerialPort(portName, baudeRate);

            strArr = list[1].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            _4202SerialPort = new SerialPort(portName, baudeRate);

            strArr = list[2].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            TrainEndSerialPort = new SerialPort(portName, baudeRate);

            strArr = list[3].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            LbjSerialPort = new SerialPort(portName, baudeRate);

            strArr = list[4].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            GsmFunSerialPort = new SerialPort(portName, baudeRate);

            strArr = list[5].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            TaxSerialPort = new SerialPort(portName, baudeRate);

            strArr = list[6].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            GSM_RModPort = new SerialPort(portName, baudeRate);

            strArr = list[7].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            PocsagCodePort = new SerialPort(portName, baudeRate);

            strArr = list[8].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            PowerPort = new SerialPort(portName, baudeRate);

            strArr = list[9].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            OSP5 = new SerialPort(portName, baudeRate);

            strArr = list[10].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            LbjNorSerialPort = new SerialPort(portName, baudeRate);

            strArr = list[11].Split(new Char[] { ',' });
            portName = strArr[0].Trim();
            baudeRate = int.Parse(strArr[1].Trim());
            LbjControlPort = new SerialPort(portName, baudeRate);
        }
    }
}
